package com.app.mapper;

import com.app.model.ConsumptionVoucher;
import com.app.model.UserModel;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 消费多送系统分成券记录 Mapper 接口
 * </p>
 *
 * @author yoominic
 * @since 2024-07-21
 */
public interface ConsumptionVoucherMapper extends BaseMapper<ConsumptionVoucher> {


    @Select("select  v.*\n" +
            "from tb_consumption_voucher v\n" +
            "left join tb_consumption_voucher_share vs on v.id = vs.voucher_id\n" +
            "where v.status not in ('4','5') and vs.shared_userid = #{sharedUserId}")
    ConsumptionVoucher getConsumptionVoucherBySharedUserId(Integer sharedUserId);


    @Update(" UPDATE tb_consumption_voucher " +
            " SET status = 5 " +
            " WHERE expiration_time < NOW() AND status NOT IN (4, 5); ")
    void UpdateExpireConsumptionVoucher();

}
